package emulator.unittest.hardware.nmos6502.commands;


import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.TYA;
import emulator.hardware.nmos6502.operands.NoOperand;

public class TYATest {

	private Cpu6502 cpu;
	private TYA tya;

	@Before
	public void setUp() throws Exception {
		cpu = new Cpu6502();
		tya = new TYA();
	}

	@Test
	public void testTransferZero() throws EmulatorException {
		executeAndcheckTYA(0, Flags6502.FLAG_ZERO);
	}

	@Test
	public void testTransferPositive() throws EmulatorException {
		executeAndcheckTYA(5, 0);
	}

	@Test
	public void testTransferNegative() throws EmulatorException {
		executeAndcheckTYA(0x81, Flags6502.FLAG_NEGATIVE);
	}

	private void executeAndcheckTYA(int target, int expected_flags)	throws EmulatorException {
		cpu.setY(new HwByte(target));
		cpu.setAccu(new HwByte(0xFF));
		tya.execute(cpu, new NoOperand());
		assertEquals(new HwByte(target), cpu.getY());
		assertEquals(new HwByte(target), cpu.getAccu());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}
}
